﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                if (Session["user"] == null)
                    Response.Redirect("Default.aspx");
                else
                    aAdmin.InnerHtml = ((Employee)Session["user"]).Username;


            }
        }
        protected void aLogout_Click(object sender, EventArgs e)
        {
            dataDataContext dc = new dataDataContext();
            try
            {
                Employee em = dc.Employees.Single(a => a.EmployeeID == ((Employee)Session["user"]).EmployeeID);
                em.TimeLogin = DateTime.Now;
                dc.SubmitChanges();
            }
            catch (Exception)
            {
                Response.Redirect("Default.aspx");
            }

            Session.Remove("user");
            Response.Cookies.Remove("userinfo");
            Response.Redirect("Default.aspx");
        }
    }
}